package com.galaxy.coupon.controller;

import com.galaxy.common.core.domain.R;
import com.galaxy.common.core.validate.AddGroup;
import com.galaxy.common.core.validate.EditGroup;
import com.galaxy.common.log.annotation.Log;
import com.galaxy.common.log.enums.BusinessType;
import com.galaxy.common.mybatis.core.page.PageQuery;
import com.galaxy.common.mybatis.core.page.TableDataInfo;
import com.galaxy.common.web.core.BaseController;
import com.galaxy.coupon.domain.bo.PointsExchangeRuleBo;
import com.galaxy.coupon.domain.vo.PointsExchangeRuleVo;
import com.galaxy.coupon.service.IPointsExchangeRuleService;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 积分兑换规则Controller
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/exchange")
public class PointsExchangeRuleController extends BaseController {

    private final IPointsExchangeRuleService pointsExchangeRuleService;

    /**
     * 查询积分兑换规则列表
     */
    @GetMapping("/list")
    public TableDataInfo<PointsExchangeRuleVo> list(PointsExchangeRuleBo bo, PageQuery pageQuery) {
        return pointsExchangeRuleService.queryPage(bo, pageQuery);
    }

    /**
     * 获取积分兑换规则详细信息
     */
    @GetMapping("/{id}")
    public R<PointsExchangeRuleVo> getInfo(@NotNull(message = "主键不能为空") @PathVariable Long id) {
        return R.ok(pointsExchangeRuleService.getInfo(id));
    }

    /**
     * 新增积分兑换规则
     */
    @Log(title = "积分兑换规则", businessType = BusinessType.INSERT)
    @PostMapping
    public R<Void> add(@Validated(AddGroup.class) @RequestBody PointsExchangeRuleBo bo) {
        return toAjax(pointsExchangeRuleService.insertByBo(bo));
    }

    /**
     * 修改积分兑换规则
     */
    @Log(title = "积分兑换规则", businessType = BusinessType.UPDATE)
    @PutMapping
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody PointsExchangeRuleBo bo) {
        return toAjax(pointsExchangeRuleService.updateByBo(bo));
    }

    /**
     * 删除积分兑换规则
     */
    @Log(title = "积分兑换规则", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空") @PathVariable Long[] ids) {
        return toAjax(pointsExchangeRuleService.deleteById(ids[0]));
    }
}
